package com.fdb.efp.esb.service.impl.wsd.firstnotice;

import com.alibaba.fastjson.JSONObject;
import com.fdb.efp.esb.common.client.resp.EsbRespServiceBean;
import com.fdb.efp.esb.common.constant.EsbBizEnums;
import com.fdb.basic.framework.core.constant.ESBConstant;
import com.fdb.basic.framework.core.exception.ESBException;
import com.fdb.basic.framework.core.util.TraceUtil;
import com.fdb.efp.esb.service.bo.req.wsd.firstnotice.FirstApproveNoticeReqBean;
import com.fdb.efp.esb.service.bo.resp.wsd.firstnotice.FirstApproveNoticeRespBean;
import com.fdb.efp.esb.service.client.ESBClientFactory;
import com.fdb.efp.esb.service.facade.wsd.firstnotice.FirstApproveNoticeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service("firstApproveNoticeService")
public class FirstApproveNoticeServiceImpl implements FirstApproveNoticeService {
    private static Logger logger = LoggerFactory.getLogger(FirstApproveNoticeServiceImpl.class);

    @Override
    public FirstApproveNoticeRespBean firstCreditNotice(FirstApproveNoticeReqBean firstApproveNoticeReqBean) throws ESBException {
        logger.info("======>调用网商贷初审通知接口【" + firstApproveNoticeReqBean.getRqsIdmptntID() + "_20120002_05】开始<======");
        FirstApproveNoticeRespBean firstApproveNoticeRespBean = null;
        TraceUtil.clear();
        try {
            EsbRespServiceBean recvBean = ESBClientFactory.buildClient()
                    .withBody(firstApproveNoticeReqBean)
                    .withTradeNo(ESBConstant.TRADE_NO_20120002)
                    .withScene(ESBConstant.SCENE_NO_05)
                    .create()
                    .sendAndReceive();
            if (EsbBizEnums.RetCodeEnum.SUCCESS.VALUE.equals(recvBean.getSysHead().getRetInfArry().get(0).getRetCd())) {
                // 这里有错
                firstApproveNoticeRespBean = recvBean.getBody(FirstApproveNoticeRespBean.class);
            } else {
                throw new ESBException(recvBean.getSysHead().getRetInfArry().get(0).getRetMsg());
            }
            logger.info("调用网商贷初审通知接口【20120002_05】结束，返回信息：" + JSONObject.toJSONString(firstApproveNoticeRespBean));
        } catch (Exception e) {
            logger.error("调用网商贷初审通知接口【20120002_05】出现异常：" + e.getMessage());
            throw new ESBException("调用网商贷初审通知接口【20120002_05】出现异常：" + e.getMessage());
        } finally {
            logger.info("======>调用网商贷初审通知接口【" +  firstApproveNoticeReqBean.getRqsIdmptntID() + "_20120002_05】结束<======");
        }
        return firstApproveNoticeRespBean;
    }
}